﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using NGen;
using NGen.Managers.GameObject;
using NGen.Systems.Graphics;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using NGen.Managers.Collision;
using Psych.Objects.Character;
using Psych.Misc;

namespace Psych.Objects.Enemies
{
    class GameObjectSlender : GameObject2D, ICollidable2D
    {
        #region properties

        public int health { get; protected set; }
        public Vector2 position { get; protected set; }

        #endregion

        #region fields

        public AnimatedSprite slender;
        private SpriteEffects spriteEffect;
        private SpriteBatch spriteBatch;
        private BoundingBox m_boundingBox;

        #endregion

        #region GameObject2D implementation

        /// <summary>
        /// 	_Initialize this enemy
        /// </summary>
        protected override void _Initialize()
        {
            spriteBatch = new SpriteBatch(GameEngine.GraphicsDevice);
            position = new Vector2(250, 250);

            slender = new AnimatedSprite(GameEngine.GameContent.Load<Texture2D>("Content\\Enemies\\slender_spritesheet00"), new Point(167, 250), new Point(13, 1), 0.10f);

            health = 100;

            m_position.X = 1000;
            m_position.Y = 200;
            m_zDepth = 0.999f;

            m_boundingBox = new BoundingBox(new Vector3(), new Vector3(167, 250, 1.0f));

            if (m_texture != null)
            {
                m_textureOffset.X = m_texture.Height / 2.0f;
                m_textureOffset.Y = m_texture.Width / 2.0f;
            }

            //spriteEffect = SpriteEffects.FlipHorizontally;

            base._Initialize();

        }

        protected override void _Update(GameTime p_gameTime)
        {
            slender.Update(p_gameTime);

            if (health <= 0)
            {
                GameEngine.GetService<IManagerCollision2D>().UnRegisterCollidable(Id);
                Destroy(Id);
            }
        }

        protected override void _Draw(GameTime p_gameTime)
        {
            GameEngine.SpriteBatch.Draw(slender.AnimationSpriteSheet, m_position, slender.GetFrame(), Color.White, 0.0f, new Vector2(0, 0), 1.0f, spriteEffect, 0.999f);
        }

        #endregion

        public BoundingBox BoundingBox
        {
            get { return m_boundingBox; }
            set { }
        }

        public void Collided(CollisionMessage2D p_objectCollidedWith)
        {
            if (p_objectCollidedWith.m_objectType == typeof(GameObjectPunch))
            {
                health += -1;
            }
        }
    }
}
